<script>
		$(document).ready(function(e) {
        	$("#newemp").click(function(){
				$("#fr_opr").load("../action/NewRoom.php");		
			});
			$("#editemp").click(function(){
				$("#fr_opr").load("../action/NewRoom.php");		
			});
			
    	});		
	</script>
           
            <h1 class="page-title">Room List</h1>
<div class="btn-toolbar">
    <!--<button class="btn btn-primary" id="newemp"><i class="icon-plus"></i> New Room</button>-->
    <a href="?tag=addroom" class="btn btn-primary btn-large"><i class="icon-plus"></i>New Room</a>
  <div class="btn-group">
  </div>
</div>

<div class="well">
    <table class="table">
      <thead>
        <tr>
          <th>#</th>
          <th>Room Number</th>
          <th>Room Type</th>
          <th>Room Price</th>
          
          <th style="width: 26px;"></th>
        </tr>
      </thead>
      <tbody>
      <?PHP 
			$dbhost = 'localhost';
			$dbuser = 'root';
			$dbpass = '';
			 $rec_limit = 5;
			 
			 $opr="";
			 
			 if(isset($_GET['opr']))
				$opr=$_GET['opr'];
			 
			 $conn = mysql_connect($dbhost, $dbuser, $dbpass);
				if(! $conn )
				{
				  die('Could not connect: ' . mysql_error());
				}
				mysql_select_db('hotel');
			$sqlc = "SELECT count(room_id) FROM room_tbl ";
			
						
			$retval = mysql_query( $sqlc, $conn );
			if(! $retval )
				{
				  die('Could not get data: ' . mysql_error());
				}	
			$row = mysql_fetch_array($retval, MYSQL_NUM );
			$rec_count = $row[0];
			
			if( isset($_GET{'page'} ) )
			{
			   $page = $_GET{'page'} ;
			   $offset = $rec_limit * $page ;
			}
			else
			{
			   $page = 0;
			   $offset = 0;
			}
			
			$left_rec = $rec_count - ($page * $rec_limit);
			$sql = "SELECT * FROM room_tbl where active=1 " .
				   "LIMIT $offset, $rec_limit";
				   
			$retval = mysql_query( $sql, $conn );
			if(! $retval )
			{
			  die('Could not get data: ' . mysql_error());
			}
				   
			while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
			{
		 ?>
        <tr>       
        	         
          <td><?php echo $row['room_id']; ?></td>
          <td><?php echo $row['room_no']; ?></td>
          <td><?php echo $row['room_type']; ?></td>
          <td><?php echo $row['room_price']; ?></td>
          
          <td>
              <a href="?tag=editroom&rid=<?php echo $row['room_id']; ?>" id="editemp"><i class="icon-pencil"></i></a>
              <a href="#myModal1" href="?tag=viewrom&rid=<?php echo $row['room_id']; ?>"  role="button" data-toggle="modal"><i class="icon-remove"></i></a>
          </td>
          
        </tr>
        <?php } 
			
				mysql_close($conn);
		?>
        
      </tbody>
    </table>
</div>
<div class="pagination">
    <ul>
    
    <?php if($rec_count>0){
		$p="";
				
		if(isset($_GET['page']))
			$p=$_GET['page'];
		
		
		$page=$rec_count/5;
		$a=$rec_count%5;
		if($a>0){ $page+=1;}
	?>
    <li><a id="pagen" href="?tag=viewrom&page=<?php if ($p>0){echo $p-1;}else echo 0; ?> " >Prev</a></li>
    <?php
		for($i=0;$i<=$page-1;$i++){	
	?>        
        	<li><a id="pagen" href="?tag=viewrom&page=<?php echo $i; ?>"><?php $offset=$i*$rec_limit; echo $i; ?></a></li>               
        
    <?php }} ?>
			
    <li><a id="pagen" href="?tag=viewrom&page=<?php if ($p<$page){echo $p+1;}else echo $page; ?> " >Next</a></li>
		
    </ul>
</div>
<div>
<?php 
	if(isset($_POST['btndel'])){
		echo $row['room_id'];
		echo"AAA";
	}

?>
</div>

<div class="modal small hide fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Delete Confirmation</h3>
  </div>
  <div class="modal-body">    
    <p class="error-text"><i class="icon-warning-sign modal-icon"></i>Are you sure you want to delete this?</p>
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
    <button name="btndel" class="btn btn-danger" data-dismiss="modal">Delete</button>
  </div>
</div>